<?php

namespace App\Console;

use App\Http\Service\RedisService;
use App\Utils\MyRabbitMQ;
use Illuminate\Console\Command;

class DemoConsumer extends Command
{
    protected $signature = 'rabbitmq:queue-test1';
    protected $description = 'Start rabbitmq:queue-test1 work';

    protected $myRabbitMQ;

    protected $redisService;

    protected $queue_name = 'test1';

    public function __construct()
    {
        parent::__construct();
    }

    public function handle()
    {
        $this->myRabbitMQ = MyRabbitMQ::getInstance();
        $call_back = function ($msg) {
            $this->redisService = new RedisService();
            $this->redisService->consumerDemoMQ($msg);
        };
        // 消费队列 这里未做消费成功的监听 让他自动处理
        $this->myRabbitMQ->consumeMessage($this->queue_name, $call_back, true);
    }
}
